local ziqu = fk.CreateSkill {

  name = "joy__ziqu",

  tags = {  },

}



ziqu:addEffect(fk.DamageCaused, {
  name = "joy__ziqu",
  anim_type = "control",
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(ziqu.name) then
      return not table.contains(player:getTableMark(ziqu.name.."-round"), data.to.id)
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, ziqu.name, nil, "#joy__ziqu-invoke::"..data.to.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local mark = player:getTableMark(ziqu.name.."-round")
    table.insert(mark, data.to.id)
    room:setPlayerMark(player, ziqu.name.."-round", mark)
    room:doIndicate(player.id, {data.to.id})
    if not data.to:isNude() then
      local ids = table.filter(data.to:getCardIds("he"), function(id)
        return table.every(data.to:getCardIds("he"), function(id2)
          return Fk:getCardById(id).number >= Fk:getCardById(id2).number end) end)
      local card = room:askForCard(data.to, 1, 1, true, ziqu.name, false, ".|.|.|.|.|.|"..table.concat(ids, ","), "#joy__ziqu-give:"..player.id)
      if #card > 0 then
        card = card[1]
      else
        card = table.random(ids)
      end
      room:obtainCard(player, card, true, fk.ReasonGive)
    end
    return true
  end
})

return ziqu